package com.dnjn.mes.biz.assist;

import com.dnjn.mes.biz.Const;
import com.dnjn.mes.biz.enums.MaintainType;
import com.dnjn.mes.biz.service.IMesWorkpieceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MaintainHandler {

    @Autowired
    IMesWorkpieceService workpieceService;

    @Scheduled(cron = "0 0 0/1 * * ? ")
    //@Scheduled(cron = "0 0/1 * * * ? ") /*for test*/
    public void handleTask() {
        log.info("---- start schedule---------------------------------");
        //机器使用时长
        workpieceService.updateTimeSpentByMaintainType(1.0, MaintainType.COMMON);

    }

    //每小时执行一次
    @Scheduled(cron = "0 0 */1 * * ? ")
    public void handleWorkpiceTask() {
        log.info("---- start 监听工件状态---------------------------------");
        //监听工件状态，判断状态写入message表记录
        workpieceService.handleWorkpiceTask();

    }
}
